package com.lk.theurlpro.dao;

import com.lk.theurlpro.pojo.Allurls;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author lk
 * @date 2020/2/5 0005 19:18
 *
 *  int choice 0/1
 *      0 表示 未放入回收站urls
 *      1 表示 回收站内的urls
 */
@Mapper
public interface AllUrlsMapper {

    @Select("select * from allurls where  remarks = #{choice} ")
    List<Allurls> findAll(int choice);

    @Insert(" insert into allurls ( u_title , url, type ,remarks ,date) values (#{u_title},#{url},#{type},0,#{date}) ")
    int save(Allurls allurls);

    @Select("select * from allurls where u_id= #{u_id} ")
    Allurls get(@Param("u_id") int u_id );

    @Update("update allurls set u_title=#{u_title},url=#{url},type=#{type},detail=#{detail},date=#{date} where u_id=#{u_id} ")
    int update(Allurls allurls);

    @Select("select * from  allurls where u_title like concat('%',#{u_title},'%') and remarks = #{choice} ")
    List<Allurls> findByTitle(@Param("u_title") String u_title,@Param("choice") int choice);

    @Select("select * from  allurls where type like concat('%',#{type},'%') and remarks = #{choice}  ")
    List<Allurls> findByType(@Param("type") String type,@Param("choice") int choice);

    @Select("select * from  allurls where date like concat('%',#{date},'%') and remarks = #{choice}  ")
    List<Allurls> findByDate(@Param("date") String date,@Param("choice") int choice);

    // 打标记,表示放入回收站  以及  恢复操作，将回收站内的网址恢复
    @Update(" update allurls set remarks = #{choice} where u_id= #{u_id} ")
    void sign(@Param("u_id") int u_id,@Param("choice") int choice );

    // 删除
    @Delete("delete from allurls where u_id = #{u_id}")
    void delete(int u_id);

    // 更新存档时间
    @Update("update allurls set date=#{date} where u_id = #{u_id} ")
    void updateTime(@Param("u_id") int u_id,@Param("date") String date);
}
